{extend name="template/base" /}
{block name="content"}
{php}
use think\Db;
{/php}
<div class="page-container">
    {include file="send_form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
                                    <a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/dispatch_traveler_group/export_to_excel/dis_status/proceed',$searchCondition)}" >excel导出</a>
            <!--{tp:menu menu="add" /}-->
            <!--<a class="btn btn-primary radius mr-5" href="{:url('/admin/dispatch_traveler_group/export_to_excel',$searchCondition)}"  >excel导出</a>-->
            <!--<a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/dispatch_traveler_group/export_to_excel',$searchCondition)}" >excel导出</a>-->
            <!--<a class="btn btn-primary radius mr-5" id="xuan" style="display: none;"  href="javascript:;" onclick="xuan()">excel导出</a>-->
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="send_th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="text-c">
            {include file="send_td" /}
            <td class="f-14">
                <a title="派车单信息" href="javascript:;" onclick="layer_open('派车单信息','/admin/dispatch_traveler_group/dispatch_details/group_id/{$vo.id}')" style="text-decoration:none" class="ml-5 label label-warning radius">派车单信息</a>
                <a href="javascript:;" onclick="accomplish('/admin/dispatch_traveler_group/accomplish/id/{$vo.id}')" class="label label-warning radius" title="确认完成">确认完成</a>
                <!--{if empty($vo['driver_confirm'])}-->
                 <!--<a href="javascript:;" onclick="accept('/admin/dispatch_traveler_group/accept/group_id/{$vo.id}')" class="label label-warning radius" title="司机接受">司机接受</a>-->
                <!--{/if}-->
                <!--<a href="javascript:;" onclick="reset_group('/admin/dispatch_traveler_group/reset_group/group_id/{$vo.id}')" class="label label-warning radius" title="取消司机">取消司机</a>-->
                <!--<a title="更换司机" href="javascript:;" onclick="layer_open('更换司机','/admin/dispatch_traveler_group/change_driver/dis_id/{$vo.id}/du_id/{$vo.driver_user_id}/oid/{$vo.oids}/is_rej/1')" style="text-decoration:none" class="ml-5 label label-warning radius">更换司机</a>-->

                <a title="重新分配司机" href="javascript:;" onclick="layer_open('重新分配司机','/admin/dispatch_traveler_group/reallocate/group_id/{$vo.id}')" style="text-decoration:none" class="label label-warning radius">重新分配司机</a>
                {if $vo.is_suspend ==2}
                <a title="申请中止" href="javascript:;" onclick="layer_open('申请中止','/admin/dispatch_traveler_group/change_driver/dis_id/{$vo.id}/du_id/{$vo.driver_user_id}/oid/{$vo.oids}/is_rej/2')" style="text-decoration:none" class="ml-5 label label-warning radius">申请中止</a>
                <!--<a title="重新分配司机" href="javascript:;" onclick="layer_open('重新分配司机','/admin/dispatch_traveler_group/reallocate/group_id/{$vo.id}')" style="text-decoration:none" class="label label-warning radius">重新分配司机</a>-->
                {/if}
                <!--{if !empty($vo['reverse_id'])}-->
                <!--<a title="变动历史" href="javascript:;" onclick="layer_open('变动历史','/admin/dispatch_traveler_group/suspend_order/group_id/{$vo.id}')" style="text-decoration:none" class="label label-warning radius">变动历史</a>-->
                <!--{/if}-->
 				<a title="编辑" href="javascript:;" onclick="layer_open('编辑','/admin/dispatch_traveler_group/dispatch_edit/id/{$vo.id}')" style="text-decoration:none" class="ml-5 label label-warning radius">编辑</a>
                {php}
                    $exceptional_order=get_exceptional_order($vo['id']);
                {/php}
                <!--{if condition="$exceptional_order"}-->
                    <!--<a title="编辑选项" href="javascript:;" onclick="layer_open('编辑选项','/admin/dispatch_traveler_group/exceptional/group_id/{$vo.id}')" style="text-decoration:none" class="ml-5 label label-warning radius">异常信息</a>-->
                <!--{/if}-->

                <!--{$vo.status|show_status=$vo.id}-->
                <!--<a title="进行中编辑" href="javascript:;" onclick="layer_open('进行中编辑','/admin/dispatch_traveler_group/proceedEdit/id/{$vo.id}')" style="text-decoration:none" class="ml-5"><i class="Hui-iconfont">&#xe6df;</i></a>-->
               
			    <!--{tp:menu menu='sdelete' /}-->
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>

{/block}

{block name="script"}
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script>

    //申请中止
    function apply_suspension(id) {
        var url = '/admin/dispatch_traveler_group/suspension';
        var suspensionUrl = url + '/group_id/' + id
        if (!id){
            layer.msg('缺少必要的参数');
        }
        $.ajax({
            type: 'get',
            url: url,
            data:{ group_id: id },
            success: function (data) {
                if (data.code == 1){
                    layer.msg(data.msg)
                    return false
                }else{
                    layer_open('申请中止',suspensionUrl)
                }
            }
        })
    }
    function reset_group(url) {
        $.ajax({
            type: 'POST',
            url: url,
            data: null,
            success: function (re){
                layer.msg(re.msg, {
                    time: 2000, //2s后自动关闭
                },function () {
                    //关闭后刷新
                    location.reload();
                });
            },
        });
    }
    function settlement(url) {
        $.ajax({
            type: 'POST',
            url: url,
            data: null,
            success: function (re){
                layer.msg(re.msg, {
                    time: 2000, //2s后自动关闭
                },function () {
                    //关闭后刷新
                    location.reload();
                });
            },
        });
    }
    function reject_settlement(url) {
        $.ajax({
            type: 'POST',
            url: url,
            data: null,
            success: function (re){
                layer.msg(re.msg, {
                    time: 2000, //2s后自动关闭
                },function () {
                    //关闭后刷新
                    location.reload();
                });
            },
        });
    }
    function accomplish(url) {
        $.ajax({
            type: 'POST',
            url: url,
            data: null,
            success: function (re){
                if(re.msg) {
                    layer.msg(re.msg, {
                        time: 2000, //2s后自动关闭
                    }, function () {
                        //关闭后刷新
                        location.reload();
                    });
                }else{
                    layer_open('司机已完成','/admin/pub/role/id/1')
                }
            },
        });
    }
    function accept(url) {
        $.ajax({
            type: 'POST',
            url: url,
            data: null,
            success: function (re){
                if(re.msg) {
                    layer.msg(re.msg, {
                        time: 2000, //2s后自动关闭
                    }, function () {
                        //关闭后刷新
                        location.reload();
                    });
                }else{
                    layer_open('司机已接受','/admin/pub/role/id/1')
                }
            },
        });
    }
    $(function () {
        $("[name='car_form']").find("[value='{$Request.param.car_form}']").attr("selected", true);
    })

    //全选
    $('#checkAlls').bind("click", function () {
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked
        if (sonChecked && allChecked){
            $('#xuan').css('display','inline') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        }else{
            $('#xuan').css('display','none')
            $('#sou').css('display','inline')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    // 单选
    $("input[name='id[]']").bind('click', function () {
        var radioData =  $("input:checked[name='id[]']");
        // 选择数据的长度
        var len = radioData.serializeArray().length;
        if (len > 0) {
            $('#xuan').css('display','inline') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display','none')
            $('#sou').css('display','inline')
            $('#checkAlls').prop('checked',false); // 取消选择全选按钮
        }
        // console.log('你点击了单选')
        // console.log('点击的结果为：', this.checked)
        // console.log('你选择的数据是', radioData.serializeArray())
        // console.log('你选择的数据长度是',len)
    });

    function xuan() {
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        dataArr.push({name: 'search',value: 'proceed'})
        // console.log('选择的数据是', checkData.length)
        // console.log('选择的数据是', checkData.serializeArray())
        // console.log('选择的数组是', dataArr)
        $.ajax({
            type: 'post',
            url: '/admin/dispatch_traveler_group/export_to_excel',
            data: dataArr,
            success: function (res) {
                if (res.code == 5){
                    // console.log('data', res);
                    location.href = res.msg; // 下载文件
                    // 删除文件
                    unclinkFile(res.msg)
                    layer.msg('导出数据成功');
                } else {
                    layer_open('excel导出数据','/admin/pub/role/id/1')
                }
            }
        });
    }
    var  value = 1;
    setTimeout(unclinkFile,1200000,value); // 延迟20分钟1200000
    // 15分钟后删除文件-900000
    function unclinkFile(val) {
        console.log(val)
        setTimeout(function () {
            // 删除文件
            $.ajax({
                type: 'post',
                url: '/admin/order/del',
                data: {val:val},
                success: function (data) {
                    console.log('data', data)
                    if (data.code != 5) {
                        console.log('删除失败', data.msg)
                    }
                }
            })
        },120000,val); // 2分钟后执行
    }
</script>

<script>
    function driverInfo(id) {
        var url = '/admin/driver/details';
        if (!id){
            layer.msg('缺少必要的参数');
        }
        $.ajax({
            type: 'get',
            url: url,
            data:{ id: id },
            success: function (data) {
                if (data.code == 1){
                    layer.msg(data.msg)
                    return false
                }else{
                    layer_open('详细资料','/admin/driver/details/id/'+id,{w:'1300px',h:'750px'})
                }
            }
        })
    }
</script>
{/block}